﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProtoBuf;
using System.IO;

class ProtoHelper
    {
    //protobuf的序列化
  public  static byte[] Serialize<T>(T t)where T: IExtensible
    {
        using (MemoryStream stream = new MemoryStream())
        {
            Serializer.Serialize<T>(stream, t);
            return stream.ToArray();
        }
    }
    //protobuf的反序列化
   public static T Deserialize<T>(byte[] bytes)where T: IExtensible
    {
        using (MemoryStream ms = new MemoryStream(bytes))
        {
            T p = Serializer.Deserialize<T>(ms);
            return p;
        }
    }
}

